package net.stogi.unicore.beyond.back.bootstrap.model;

import net.stogi.unicore.beyond.api.model.InputType;
import net.stogi.unicore.beyond.api.model.OutputType;
import net.stogi.unicore.beyond.api.model.ValueType;
import net.stogi.unicore.beyond.back.dao.InputTypeDao;
import net.stogi.unicore.beyond.back.dao.OutputTypeDao;


public class BootStrapModel {

	private InputTypeDao inputTypeDao;

	private OutputTypeDao outputTypeDao;

	public BootStrapModel(InputTypeDao inputTypeDao, OutputTypeDao outputTypeDao) {
		this.inputTypeDao = inputTypeDao;
		this.outputTypeDao = outputTypeDao;
	}
	
	public void bootstrapInputTypes() throws Exception {
		InputType textfield = new InputType("textfield");
		textfield.addProperty("empty", ValueType.BOOLEAN).setDefaultValue("true");
		textfield.addProperty("max", ValueType.INTEGER).setDefaultValue("100");
		textfield.addProperty("min", ValueType.INTEGER).setDefaultValue("0");
		textfield.addProperty("regex", ValueType.STRING);
		inputTypeDao.save(textfield);

		InputType integerfield = new InputType("integerfield");
		integerfield.addProperty("empty", ValueType.BOOLEAN).setDefaultValue("true");
		integerfield.addProperty("max", ValueType.INTEGER).setDefaultValue("30000");
		integerfield.addProperty("min", ValueType.INTEGER).setDefaultValue("-30000");
		inputTypeDao.save(integerfield);

		InputType richtextfield = new InputType("richtextfield");
		richtextfield.addProperty("empty", ValueType.BOOLEAN).setDefaultValue("true");
		richtextfield.addProperty("max", ValueType.INTEGER).setDefaultValue("500");
		richtextfield.addProperty("min", ValueType.INTEGER).setDefaultValue("0");
		richtextfield.addProperty("regex", ValueType.STRING);
		inputTypeDao.save(richtextfield);

		InputType doublefield = new InputType("doublefield");
		doublefield.addProperty("empty", ValueType.BOOLEAN).setDefaultValue("true");
		doublefield.addProperty("max", ValueType.DOUBLE).setDefaultValue("1000000.0");
		doublefield.addProperty("min", ValueType.DOUBLE).setDefaultValue("-1000000.0");
		inputTypeDao.save(doublefield);

		InputType datefield = new InputType("datefield");
		datefield.addProperty("empty", ValueType.BOOLEAN).setDefaultValue("true");
		datefield.addProperty("first", ValueType.DATE);
		datefield.addProperty("last", ValueType.DATE);
		datefield.addProperty("pattern", ValueType.STRING).setDefaultValue("yyyy-MM-dd");
		inputTypeDao.save(datefield);

		InputType combofield = new InputType("combofield");
		combofield.addProperty("empty", ValueType.BOOLEAN).setDefaultValue("true");
		combofield.addProperty("values", ValueType.LIST).setDefaultValue("value1,value2,value3");
		inputTypeDao.save(combofield);
	}

	public void bootstrapOutputTypes() throws Exception {
		OutputType filedownloadfield = new OutputType("filedownloadfield");
		outputTypeDao.save(filedownloadfield);

		OutputType imageviewfield = new OutputType("imageviewfield");
		outputTypeDao.save(imageviewfield);

		OutputType appletviewfield = new OutputType("appletviewfield");
		outputTypeDao.save(appletviewfield);
	}
}
